//
//  QuDanHomeTopView.m
//  QuDanOEM
//
//  Created by mac on 2021/10/23.
//

#import "QuDanHomeTopView.h"
#import "QuDanSearchTextfiled.h"
#import "UIButton+POImagePosition.h"
@interface QuDanHomeTopView ()

@property (nonatomic,strong)UIButton *addressBtn;

@property (nonatomic,strong)QuDanSearchTextfiled *searchTextField;

@end

@implementation QuDanHomeTopView

- (QuDanSearchTextfiled *)searchTextField
{
    if (!_searchTextField) {
        _searchTextField = [[QuDanSearchTextfiled alloc]init];
        _searchTextField.font = [UIFont systemFontOfSize:15];
        _searchTextField.textColor = HEXCOLOR(0x999999);
        _searchTextField.layer.cornerRadius = 16;
        _searchTextField.clipsToBounds = YES;
        _searchTextField.backgroundColor = QD_RGB(245, 245, 245);
        _searchTextField.logoColor = HEXCOLOR(0x999999);
        NSMutableAttributedString *attribuedString = [[NSMutableAttributedString alloc]initWithString:@"搜索用户/技能"];
        [attribuedString addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:HEXCOLOR(0x999999)} range:NSMakeRange(0, attribuedString.length)];
        _searchTextField.attributedPlaceholder = attribuedString;
    }
    return _searchTextField;
}
- (UIButton *)addressBtn
{
    if (!_addressBtn) {
        _addressBtn = [[UIButton alloc]init];
        [_addressBtn setTitle:@"成都" forState:UIControlStateNormal];
        [_addressBtn setTitleColor:QD_RGB(57, 57, 59) forState:UIControlStateNormal];
        _addressBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_addressBtn setImage:[UIImage imageNamed:@"home_up"] forState:UIControlStateNormal];
        [_addressBtn addTarget:self action:@selector(actionAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_addressBtn setImagePosition:(POImagePositionRight) withInset:2];
        [_addressBtn sizeToFit];
    }
    return _addressBtn;
}
-(void)actionAddressBtn:(UIButton *)btn
{
    NSLog(@"actionAddressBtn btn");
    if (self.QuDanHomeTopViewAddressBlock) {
        self.QuDanHomeTopViewAddressBlock();
    }
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    [self addSubview:self.addressBtn];
    [self.addressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self).offset(Height_StatusBar/2);
        make.left.offset(15);
        make.width.offset(60);
        make.height.offset(30);
    }];
    [self addSubview:self.searchTextField];
    [self.searchTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self).offset(Height_StatusBar/2);
        make.left.mas_equalTo(self.addressBtn.mas_right).offset(20);
        make.right.offset(-15);
        make.height.offset(30);
    }];
    WEAKSELF
    [self.searchTextField setClickSeachBlock:^{
        if (weakSelf.QuDanHomeTopViewSearchBlock) {
            weakSelf.QuDanHomeTopViewSearchBlock();
        }
    }];
}
@end
